//
// Created on 2024/1/3.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".


#ifndef NATIVEIMAGEDEMO_SHADER_PROGRAM_H
#define NATIVEIMAGEDEMO_SHADER_PROGRAM_H

#include <string>

#include <GLES3/gl3.h>

namespace webrtc {
namespace ohos {
class ShaderProgram {
public:
    ShaderProgram(const std::string &vertexShader, const std::string &fragShader);
    ~ShaderProgram() noexcept;

    // disallow copy and move
    ShaderProgram(const ShaderProgram &other) = delete;
    void operator=(const ShaderProgram &other) = delete;
    ShaderProgram(ShaderProgram &&other) = delete;
    void operator=(ShaderProgram &&other) = delete;

    bool Valid() const
    {
        return id_ > 0;
    }
    bool Use() const
    {
        GLint ret = glGetError();
        glUseProgram(id_);
        if(ret != GL_NO_ERROR) {
            return false;
        }
        return true;
    }

    void SetBool(const std::string &name, bool value);
    void SetInt(const std::string &name, int value);
    void SetFloat(const std::string &name, float value);
    void SetFloat4v(const std::string &name, float *values, int cnt);
    void SetMatrix4v(const std::string &name, float *matrix, int cnt, bool transpose=false);
    GLint GetAttribLocation(const std::string &name);

private:
    void CheckCompileErrors(GLuint shader, const std::string &shaderType);
    GLuint id_ = 0;
};
}
} // namespace webrtc::ohos
#endif //NATIVEIMAGEDEMO_SHADER_PROGRAM_H
